home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 9.5 KB | 283 lines | [TEXT/MPS ] |
- // UObject.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UOBJECT__
- #define __UOBJECT__
-
- // MacApp
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #ifndef __UCLASSDESC__
- #include "UClassDesc.h"
- #endif
-
- #ifndef __UPOINTEROBJECT__
- #include "UPointerObject.h"
- #endif
-
- // ANSI
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TObject;
- class TStream;
- class TDependencySpace;
-
- //----------------------------------------------------------------------------------------
- // Typedefs
- //----------------------------------------------------------------------------------------
-
- enum ComparisonResult
- {
- kLessThan = -1,
- kEqual = 0,
- kGreaterThan = 1
- };
-
- typedef long HashValue;
-
- //----------------------------------------------------------------------------------------
- // TObject: Definition of the system's root object
- //----------------------------------------------------------------------------------------
-
- #if (qDebug || qSym) && defined(__MWERKS__)
- #define qForceClassIDFirstHack 1
-
- // make sure CodeWarrior puts fClassID first, not the vtable
- struct ForceClassIDFirst
- {
- ClassID fClassID;
- };
- #else
- #define qForceClassIDFirstHack 0
- #endif
-
- #if qForceClassIDFirstHack
- class TObject : public ForceClassIDFirst
- #else
- class TObject
- #endif
- {
- MA_DECLARE_CLASS;
-
- public:
-
- #if (qDebug || qSym) && !qForceClassIDFirstHack
- ClassID fClassID; // Used to do object validation in debug mode.
- #endif
-
- //------------------------------------------------------------------------------------
- // Constructor, destructor, Initializer and I<Method>.
- //------------------------------------------------------------------------------------
-
- #if qInspector
- TObject();
- #else
- inline TObject()
- { }
- #endif
- // Constructor
-
- virtual ~TObject();
- // Destructor
-
- #if qDebug || qSym || qInspector || qTheDebugger
- void IObject();
- #else
- inline void IObject()
- { }
- #endif
- // The ancestral initializer. Should be called in the I<ClassName> chain. i.e.
- // IView -> IEventHandler -> IObject, followed by a called to <ClassName> i.e without
- // the T.
-
- //------------------------------------------------------------------------------------
- // Allocate and deallocate.
- //------------------------------------------------------------------------------------
-
- inline void* operator new(size_t size)
- { return MAOperatorNew(size); }
-
- void operator delete(void* obj);
-
- virtual TObject* Clone();
- // Makes a duplicate copy of this. The default calls this->ShallowClone, which
- // makes a literal copy of instance variables but does not attempt to clone owned
- // objects. A subclass which owns other objects should override this to clone the
- // owned objects and data structures as well.
-
- virtual void Free();
- // Called to dispose of an object. Gives object a chance to cleanup after itself.
- // Default simply calls this->ShallowFree, which makes no attempt to free instance
- // variables. Should be overridden by any class which allocates space or owns
- // other objects in its instance variables.. Be sure to call Inherited!
-
- //------------------------------------------------------------------------------------
- // Comparison
- //------------------------------------------------------------------------------------
-
- HashValue Hash() const;
-
- inline Boolean IsSame(const TObject* theObject) const
- { return this == theObject; }
- // Does a handle comparison to determine if the objects are in fact the same object
-
- virtual Boolean IsEqual(const TObject* theObject) const;
- // Must be overridden to be useful. Default implementation calls IsSame
-
- virtual ComparisonResult CompareObject(const TObject* theObject) const;
- // Compares two objects.
-
- virtual Boolean IsGreaterThan(const TObject* obj) const;
-
- virtual Boolean IsLessThan(const TObject* obj) const;
-
- inline Boolean operator<(const TObject& obj) const
- { return (this->IsLessThan(&obj)); }
- // Calls back to IsLessThan.
-
- inline Boolean operator>(const TObject& obj) const
- { return (this->IsGreaterThan(&obj)); }
- // Calls back to IsGreaterThan.
-
- inline Boolean operator>=(const TObject& obj) const
- { return (this->IsGreaterThan(&obj) || this->IsEqual(&obj)); }
- // Calls back to IsGreaterThan and IsEqual.
-
- inline Boolean operator<=(const TObject& obj) const
- { return (this->IsLessThan(&obj) || this->IsEqual(&obj)); }
- // Calls back to IsLessThan and IsEqual.
-
- inline Boolean operator ==(const TObject& obj) const
- { return (this->IsEqual(&obj)); }
- // Calls back to IsEqual.
-
- inline Boolean operator !=(const TObject& obj) const
- { return (this->IsEqual(&obj) == FALSE); }
-
- //------------------------------------------------------------------------------------
- // Change notification //••• SRF this could be removed to a mixin
- //------------------------------------------------------------------------------------
-
- void AddDependent(TObject* dependent);
- // Registers the specified object as a dependent of this object in the global
- // dependency space "gMacAppDependencies", so that it will be notified of changes
- // in this object.
-
- void RemoveDependent(TObject* dependent);
- // Remove the specified object from the list of dependents of this object in
- // the global dependency space "gMacAppDependencies".
-
- virtual void Changed(ChangeID theChange, TObject* changedBy);
- // Called to inform dependents of this object in the global dependency space
- // "gMacAppDependencies" that it has been changed.
- // "theChange" will often contain a command number.
- // "changedBy" will often contain a command object.
- // Called often, overridden rarely.
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace);
- // Informs this object that an object on which it is dependent in the global
- // dependency space "gMacAppDependencies" has been changed.
- // Called rarely, overridden often.
-
- virtual TDependencySpace* GetDependencySpace();
- // Returns the default dependency space for storing dependents of this object.
- // Returns gMacAppDependencies.
-
- virtual void SetMark(Boolean state);
- // Intended to mark (state=true) or unmark (state=false) this object. Can be used
- // by dependency spaces that require marking, and overridden by objects that store the
- // mark internally. The MacApp dependency spaces do not use this method.
-
- virtual Boolean IsMarked();
- // Intended to return true if this object is marked. Can be used
- // by dependency spaces that require marking, and overridden by objects that store the
- // mark internally. The MacApp dependency spaces do not use this method.
-
- virtual void RemoveAllDependencies();
- // Used by TObject::Free to remove all dependency relations in the global
- // dependency space "gMacAppDependencies" which involve this object, either
- // as notifier or as dependent.
-
- virtual Boolean RemoveDependenciesOnFree();
- // Default is to return true. This will allow us to optimize certain system
- // objects (like TToolBoxEvents).
-
-
-
- //------------------------------------------------------------------------------------
- // Standard signature support.
- //------------------------------------------------------------------------------------
-
- virtual IDType GetStandardSignature(); // override
- // Returns this class's standard signature.
-
- //------------------------------------------------------------------------------------
- // Stream I/O protocol support.
- //------------------------------------------------------------------------------------
-
- virtual void ReadFrom(TStream* aStream);
-
- virtual void WriteTo(TStream* aStream);
-
-
- //------------------------------------------------------------------------------------
- // Miscellaneous protocol and support methods.
- //------------------------------------------------------------------------------------
-
- inline ClassID GetClassID() const
- { return (GetClassDescDynamic())->GetClassID(); }
- // Returns the class ID of this.
-
- inline void GetClassName(ClassName& clName) const
- { (GetClassDescDynamic())->GetClassName(clName); }
- // Returns the class name of this.
-
- inline const char* GetClassName() const
- { return (GetClassDescDynamic())->GetClassName(); }
- // Returns a pointer to the class name of this.
-
- inline size_t GetClassSize() const
- { return (GetClassDescDynamic())->GetClassSize(); }
- // Returns the basic instantiation size. i.e. the size in bytes of a newly created
- // object of this class.
-
- inline const ClassDesc* GetSuperClass() const
- { return (GetClassDescDynamic())->GetBaseClass(); }
- // Returns ClassDesc for the immediate superclass. Returns NULL for TObject. If we
- // ever get MI this will have to be an enumerator.
-
- inline Boolean DescendsFrom(const ClassDesc* classDesc) const
- { return (GetClassDescDynamic())->DescendsFrom(classDesc); }
- // True if my class is a subclass of the class described by ClassDesc.
-
- inline Boolean IsSameClass(const ClassDesc* classDesc) const
- { return GetClassDescDynamic() == classDesc; }
- // True if my class is the same as the class described by ClassDesc.
-
- #if qDebugMsg
- void SubClassResponsibility();
- #else
- inline void SubClassResponsibility()
- { }
- #endif
- // Called from methods that MUST be overridden in a subclass. Signals failure.
- };
-
-
- typedef TObject* TObjectPtr;
- typedef TObjectPtr* TObjectPtrPtr;
- typedef TObjectPtrPtr* TObjectPtrHandle;
-
-
- #endif
-